FROM    ubuntu
MAINTAINER xiaogu "tongdanson@xiaogu-tech.com"


# adduser
RUN /bin/echo 'root:888888' |chpasswd
RUN useradd xiaogu -m -s /bin/bash
RUN /bin/echo 'xiaogu:888888' |chpasswd
RUN /bin/echo -e "LANG=\"en_US.UTF-8\"" >/etc/default/local

# change apt-source from alibaba.com
# RUN /bin/echo "deb http://mirrors.aliyun.com/ubuntu/ xenial main multiverse restricted universe
# deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main multiverse restricted universe
# deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main multiverse restricted universe
# deb http://mirrors.aliyun.com/ubuntu/ xenial-security main multiverse restricted universe
# deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main multiverse restricted universe
# deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main multiverse restricted universe
# deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main multiverse restricted universe
# deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main multiverse restricted universe
# deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main multiverse restricted universe">>/etc/apt/sources.list
RUN apt-get update

# python3
RUN apt-get install -y python3.5
RUN apt-get install -y python3-pip

# tools
RUN apt-get install -y git
RUN apt-get install -y vim
RUN apt-get install -y wget
#RUN apt-get install -y unzip
RUN apt-get install -y sudo
RUN apt-get install -y curl

# add xiaogu to sudoers
RUN /bin/echo "%xiaogu ALL=(ALL) NOPASSWD:ALL">>/etc/sudoers
# another way:  RUN usermode -G sudo xiaogu 
# but this need passwd first time, when using sudo
# e.g. nenew ALL=(ALL) NOPASSWS:/sbin/shutdown,/sbin/halt,/sbin/reboot

# jdk8
RUN /bin/echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/webupd8team-java.list
RUN /bin/echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
#apt-get update
#agree license by default
RUN /bin/echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
RUN apt-get update
RUN apt-get install -y oracle-java8-installer

# elasticsearch
USER xiaogu
WORKDIR /home/xiaogu
RUN mkdir project
WORKDIR project
RUN wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.tar.gz
RUN tar -zxvf elasticsearch-5.5.0.tar.gz
WORKDIR elasticsearch-5.5.0
# RUN /bin/echo "network.host: 0.0.0.0">>./bin/elasticsearch.yml # use from internet
RUN bin/elasticsearch-plugin install --batch x-pack
RUN bin/elasticsearch -d
# RUN curl -XPUT -u elastic 'http://localhost:9200/_xpack/security/user/elastic/_password' -d '{"password":"changeme"}'
# RUN curl -u elastic:changeme 'http://localhost:9200'

# download the code source
# RUN git clone git@git.oschina.net:xiaogu-tech/laioffer-lms.git
WORKDIR /home/xiaogu/project
RUN mkdir elastic
ADD ./es /home/xiaogu/project/elastic

# Expose
EXPOSE  8000

# run django project
WORKDIR elastic
# Add and install Python modules
ADD requirements.txt /home/xiaogu/project/elastic/requirements.txt
RUN pip3 install -r requirements.txt
RUN sudo pip3 install elasticsearch
#RUN python3 manage.py runserver 0.0.0.0:8000

# Run
# CMD ["python3", "home/xiaogu/project/elastic/manage.py runserver 0.0.0.0:8000"]
CMD ["/bin/bash"]

# don't know the function
# CMD     /usr/sbin/sshd -D

# run this image:3 method:  -d -->silence   -i -->interact
#docker run -it -p 8080:8000 ubuntu-es:v2 /bin/bash
#docker run -it -p 8080:8000 ubuntu-es:v22 python3 /home/xiaogu/project/elastic/manage.py runserver 0.0.0.0:8000
#docker run -it -v /home/danson/Documents/Proj/elastic_search:/data  -p 8080:8000 ubuntu-es:v22
#docker run -t -d -p 8080:8000 ubuntu-es:v22 python3 /home/xiaogu/project/elastic/manage.py runserver 0.0.0.0:8000
# ubuntu-es:v22 change CMD '/bin/bash' against ubuntu-es:v2
# ubuntu-es:v12 install more softwares against ubuntu-es:v1
# ubuntu-es:v2 is the complete version of ubuntu-es:v1
# ubuntu-es:v31 unchange the source from ubuntu.com




